package com.lcredu.homework.dao;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author 黎长容
 * @date 2025-07-17 23:51
 */
@Repository
public class GoodsDao {
    @Resource
    private JdbcTemplate jdbcTemplate;

    //查询单价
    public Float queryPrice(Integer goodsId) {
        String sql = " select price from goods2 where id = ?";
        Float price = jdbcTemplate.queryForObject(sql, Float.class,goodsId);
        return price;
    }

    //减少库存
    public void updateAmount(int id, int num) {
        String sql = "update goods2 set amount = amount - ? where id = ?";
        jdbcTemplate.update(sql, num, id);
    }
}
